import { computed } from 'vue'
import { useStore } from 'vuex'
export default function useHistory(props) {
  const store = useStore()
  const historyList = computed(() => store.state.historyList)

  const addHistory = async item => {
    store.dispatch('setSearchHistory', {
      item,
      type: 'add'
    })
  }

  const removeHistoryItem = item => {
    store.dispatch('setSearchHistory', {
      item,
      type: 'del'
    })
  }

  // 全部删除
  const removeHistory = () => {
    store.dispatch('setSearchHistory')
  }

  return {
    historyList,
    addHistory,
    removeHistoryItem,
    removeHistory
  }
}
